import Ajv, { AnySchemaObject } from 'ajv';
import {FuncKeywordDefinition} from "ajv/dist/types";

// 创建 Ajv 实例
const ajv = new Ajv();

// 自定义关键字
let kwdOrDef:FuncKeywordDefinition = {
    keyword: 'eachPropIsTrue',
    type: 'object',
    schemaType: 'boolean',
    compile: (schema: boolean, parentSchema: AnySchemaObject) => {
        return (data: Record<string, any>) => {
            return Object.values(data).every((value) => !!value);
        };
    },
};
ajv.addKeyword(kwdOrDef);

// 定义 JSON Schema
const schema = {
    type: 'object',
    eachPropIsTrue: true,
};

// 示例数据
const validData = {
    asdsad: true,
    assddasd: true,
    asdas: true,
};

// 验证数据是否符合 JSON Schema
const validate = ajv.compile(schema);
const isValid = validate(validData);

console.log(isValid); // 输出 false，因为 prop2 是 false
